package com.snail.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.snail.model.pojo.BizQuestion;
import com.snail.service.impl.QuestionByAiService;
import com.snail.model.dto.TestQuestionDTO;
import com.snail.response.BaseResponse;
import com.snail.response.ResultUtils;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ysc
 * @descrpiton 返回生成测试题的接口
 * @date 2025/7/17 11:40
 **/
@RestController
@CrossOrigin
@RequestMapping("/question")
public class TestQuestionController {
    @Autowired
    QuestionByAiService questionByAiService;

    @Operation(summary = "ai提供题目", description = "ai提供题目，data返回的是json格式，content,difficulty,answer,analysis,1-单选,2-多选,3-填空,4-判断,5-简答")
    @GetMapping(path = "/{type}/{video-id}")
    public BaseResponse<?> question(@PathVariable("type") Integer type,@PathVariable("video-id")Integer videoId) {
        try {
            List<BizQuestion> result= questionByAiService.chat(type,videoId);
            return ResultUtils.success(result);
        } catch (JsonProcessingException e) {
            e.printStackTrace(); // 或记录日志
            return ResultUtils.error(50001, "生成问题失败：" + e.getMessage());
        }

    }

    @Operation(summary = "ai根据需求提供题目", description = "")
    @GetMapping(path = "/require/{require}/{type}")
    public BaseResponse<?> reQuestion(@PathVariable("require")  String require,@PathVariable("type")  Integer type) {
        try {
            List<BizQuestion> result= questionByAiService.chatQuestion(require,type);
            return ResultUtils.success(result);
        } catch (JsonProcessingException e) {
            e.printStackTrace(); // 或记录日志
            return ResultUtils.error(50001, "生成问题失败：" + e.getMessage());
        }

    }

}
